//
//  PhotoViewController.m
//  Project1
//
//  Created by 黄珂耀 on 15/7/23.
//  Copyright (c) 2015年 黄珂耀. All rights reserved.
//

#import "PhotoViewController.h"

#define KWidth [UIScreen mainScreen].bounds.size.width
#define KHeight [UIScreen mainScreen].bounds.size.height

@interface PhotoViewController ()

@end

@implementation PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self _createCollectionView];
    [self _createNavigationBar];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideNav) name:@"hideNavigationBar" object:nil];
    
}

- (void)hideNav
{
    BOOL isHidden = !self.navigationController.navigationBarHidden;
    [self.navigationController setNavigationBarHidden:isHidden animated:YES];
}

- (void)_createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake(KWidth, KHeight - 100);
//    layout.itemSize = self.view.bounds.size;
    layout.minimumLineSpacing = 30;
    
    _photoCollectionView = [[PhotoCollectionView alloc] initWithFrame:CGRectMake(0, 0, KWidth + 30, KHeight) collectionViewLayout:layout];
    
    [self.view addSubview:_photoCollectionView];

}

- (void)_createNavigationBar
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
}

- (void)cancelAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)setPhotoURLArray:(NSArray *)photoURLArray
{    
    _photoURLArray = photoURLArray;
    
    _photoCollectionView.photoURLArray = _photoURLArray;
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_currentIndex inSection:0];
    
    [_photoCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
